<?php


namespace App\Http\Controllers\Admin;


use App\Response\Response;
use Illuminate\Http\Request;
use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;

//主播推荐管理
class RecommendController extends BaseController
{
    /**
     * @api {get} /recommend/room 房间推荐列表
     * @apiVersion 0.1.0
     * @apiName 房间推荐列表
     * @apiGroup 推荐管理
     *
     * @apiParam {int} page 第几页，默认1
     * @apiParam {int} page_size 每页显示条数，1-100之间，默认10
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "current_page": 1,
     * "data": [{
     * "id": 25,
     * "priority(优先级)": 0,
     * "recom_num(推荐次数)": 0,
     * "into_room_num(进房次数)": 0,
     * "create_time(创建时间)": "1970-01-01 08:00:00",
     * "room_code(房间号)": 2033,
     * "room_name(房间昵称)": "心安"
     * }],
     * "first_page_url": "http://www.qipaoadmin.com/recommend/room?=1",
     * "from": 1,
     * "last_page": 1,
     * "last_page_url": "http://www.qipaoadmin.com/recommend/room?=1",
     * "next_page_url": null,
     * "path": "http://www.qipaoadmin.com/recommend/room",
     * "per_page": 20,
     * "prev_page_url": null,
     * "to": 8,
     * "total": 8
     * },
     * "message": ""
     * }
     */
    public function roomList(Request $request)
    {
        $param = $request->only('page', 'page_size');
        $v = app('validator')->make($param, [
            'page' => 'integer|min:1',
            'page_size' => 'integer|min:1|max:100',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $page = $request->input('page', 1);
        $perPage = $request->input('page_size', 20);

        $list = app('repo_recommend')->getRoomList($page, $perPage);
        return Response::sendData($list);
    }

    /**
     * @api {get} /recommend/room/search 搜索房间
     * @apiVersion 0.1.0
     * @apiName 搜索房间
     * @apiGroup 推荐管理
     *
     * @apiParam {Int} room_code 房间号，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "room_id(房间id)": 2043,
     * "room_name（房间名）": "夕阳红老年聊天会所"
     * },
     * "message": ""
     * }
     */
    public function roomSearch(Request $request)
    {
        $param = $request->only('room_code');
        $v = app('validator')->make($param, [
            'room_code' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_recommend')->roomSearch($param);
        return Response::sendData($list);
    }

    /**
     * @api {post} /recommend/room/add 新增房间推荐
     * @apiVersion 0.1.0
     * @apiName 新增房间推荐
     * @apiGroup 推荐管理
     *
     * @apiParam {int} room_id 房间id，必传
     * @apiParam {int} priority 优先级，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function roomAdd(Request $request)
    {
        $param = $request->only('room_id', 'priority');
        $v = app('validator')->make($param, [
            'room_id' => 'required|integer|min:0',
            'priority' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_recommend')->roomAdd($param);
        return Response::sendData(true);
    }

    /**
     * @api {get} /recommend/room/edit_detail 编辑房间推荐数据
     * @apiVersion 0.1.0
     * @apiName 编辑房间推荐数据
     * @apiGroup 推荐管理
     *
     * @apiParam {Int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "id": 28,
     * "priority（优先级）": 1,
     * "room_code(房间号)": 5912115,
     * "room_name（房间名）": "夕阳红老年聊天会所"
     * },
     * "message": ""
     * }
     */
    public function roomEditDetail(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_recommend')->roomEditDetail($param);
        return Response::sendData($list);
    }

    /**
     * @api {post} /recommend/room/edit 编辑房间推荐
     * @apiVersion 0.1.0
     * @apiName 编辑房间推荐
     * @apiGroup 推荐管理
     *
     * @apiParam {int} id id，必传
     * @apiParam {int} room_id 房间id，必传
     * @apiParam {int} priority 优先级，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function roomEdit(Request $request)
    {
        $param = $request->only('id', 'room_id', 'priority');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
            'room_id' => 'required|integer|min:0',
            'priority' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_recommend')->roomEdit($param);
        return Response::sendData(true);
    }

    /**
     * @api {post} /recommend/room/del 删除房间推荐
     * @apiVersion 0.1.0
     * @apiName 删除房间推荐
     * @apiGroup 推荐管理
     *
     * @apiParam {int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function roomDel(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_recommend')->roomDel($param);
        return Response::sendData(true);
    }

    /**
     * @api {get} /recommend/user 主播推荐列表
     * @apiVersion 0.1.0
     * @apiName 主播推荐列表
     * @apiGroup 推荐管理
     *
     * @apiParam {int} page 第几页，默认1
     * @apiParam {int} page_size 每页显示条数，1-100之间，默认10
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "current_page": 1,
     * "data": [{
     * "id": 25,
     * "priority(优先级)": 0,
     * "recom_num(推荐次数)": 0,
     * "into_room_num(进房次数)": 0,
     * "create_time(创建时间)": "1970-01-01 08:00:00",
     * "user_code(用户编号)": 2033,
     * "nickname(用户昵称)": "心安"
     * }],
     * "first_page_url": "http://www.qipaoadmin.com/recommend/user?=1",
     * "from": 1,
     * "last_page": 1,
     * "last_page_url": "http://www.qipaoadmin.com/recommend/user?=1",
     * "next_page_url": null,
     * "path": "http://www.qipaoadmin.com/recommend/user",
     * "per_page": 20,
     * "prev_page_url": null,
     * "to": 8,
     * "total": 8
     * },
     * "message": ""
     * }
     */
    public function userList(Request $request)
    {
        $param = $request->only('page', 'page_size');
        $v = app('validator')->make($param, [
            'page' => 'integer|min:1',
            'page_size' => 'integer|min:1|max:100',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $page = $request->input('page', 1);
        $perPage = $request->input('page_size', 20);

        $list = app('repo_recommend')->getUserList($page, $perPage);
        return Response::sendData($list);
    }

    /**
     * @api {get} /recommend/user/search 搜索主播
     * @apiVersion 0.1.0
     * @apiName 搜索主播
     * @apiGroup 推荐管理
     *
     * @apiParam {Int} user_code 用户编号，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "user_id(用户id)": 2043,
     * "nickname（用户昵称）": "夕阳红老年聊天会所"
     * },
     * "message": ""
     * }
     */
    public function userSearch(Request $request)
    {
        $param = $request->only('user_code');
        $v = app('validator')->make($param, [
            'user_code' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_recommend')->userSearch($param);
        return Response::sendData($list);
    }

    /**
     * @api {post} /recommend/user/add 新增主播推荐
     * @apiVersion 0.1.0
     * @apiName 新增主播推荐
     * @apiGroup 推荐管理
     *
     * @apiParam {int} user_id 用户id，必传
     * @apiParam {int} priority 优先级，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function userAdd(Request $request)
    {
        $param = $request->only('user_id', 'priority');
        $v = app('validator')->make($param, [
            'user_id' => 'required|integer|min:0',
            'priority' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_recommend')->userAdd($param);
        return Response::sendData(true);
    }

    /**
     * @api {get} /recommend/user/edit_detail 编辑主播推荐数据
     * @apiVersion 0.1.0
     * @apiName 编辑主播推荐数据
     * @apiGroup 推荐管理
     *
     * @apiParam {Int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": {
     * "id": 28,
     * "priority（优先级）": 1,
     * "user_code(用户编号)": 5912115,
     * "nickname（用户名）": "夕阳红老年聊天会所"
     * },
     * "message": ""
     * }
     */
    public function userEditDetail(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_recommend')->userEditDetail($param);
        return Response::sendData($list);
    }

    /**
     * @api {post} /recommend/user/edit 编辑主播推荐
     * @apiVersion 0.1.0
     * @apiName 编辑主播推荐
     * @apiGroup 推荐管理
     *
     * @apiParam {int} id id，必传
     * @apiParam {int} user_id 用户id，必传
     * @apiParam {int} priority 优先级，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function userEdit(Request $request)
    {
        $param = $request->only('id', 'user_id', 'priority');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
            'user_id' => 'required|integer|min:0',
            'priority' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_recommend')->userEdit($param);
        return Response::sendData(true);
    }

    /**
     * @api {post} /recommend/user/del 删除主播推荐
     * @apiVersion 0.1.0
     * @apiName 删除主播推荐
     * @apiGroup 推荐管理
     *
     * @apiParam {int} id id，必传
     *
     * @apiSuccessExample {json} Response-Example
     * {
     * "code": 200,
     * "data": true,
     * "message": ""
     * }
     */
    public function userDel(Request $request)
    {
        $param = $request->only('id');
        $v = app('validator')->make($param, [
            'id' => 'required|integer|min:0',
        ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        app('repo_recommend')->userDel($param);
        return Response::sendData(true);
    }

}